<%@page import="com.fractalist.man.constants.ManConstants"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/includes.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>标签列表</title>
<link rel="stylesheet" href="${ctx }/css/styles.css" type="text/css" />
<script type="text/javascript" src="${ctx }/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="${ctx }/js/jquery.form.js"></script>
<jsp:include page="/common/jscalendar.jsp"></jsp:include>
<style>
.tc a {
	color: red;
}
</style>
<script>
	/**
	 * 切换用户角色
	 */
	function changeUserType(ele) {
		var value = $(ele).val();
		$("input[name='competencia']").each(function() {
			$(this).attr("checked", false);
		});
		if (value != -1) {
			$.post("${ctx}/manager/getCompetenciaRoleList.action", {
				userType : value
			}, function(data) {
				data = eval("(" + data + ")").crList;
				for ( var i = 0; i < data.length; i++) {
					var tmp = data[i];
					$("#competencia_" + tmp.competenciaId).attr("checked", true);
				}
			});
		}
	}
	/**
	 * 确定修改用户角色权限
	 */
	function changeUserRights() {
		var value = $("#userTypeSelect").val();
		if (value == -1) {
			alert("请选择一个有效的用户角色");
		} else {
			var tmp = "";
			for ( var i = 0; i < $("input[name='competencia']").size(); i++) {
				var co = $("input[name='competencia']").eq(i);
				if (co.attr("checked") == true) {
					tmp += co.val() + ",";
				}
			}
			if (tmp.length > 0) {
				tmp = tmp.substring(0, tmp.length - 1);
				$.post("${ctx}/manager/updateCompetenciaRole.action", {
					userType : value,
					desc : tmp
				}, function(data) {
					data = eval("(" + data + ")");
					alert(data.msg);
				});
			}
		}
	}
</script>
</head>
<body>
	<div id="wrapper">
		<div id="content_wrap">
			<div class="tabs_content">
				<div class="active_tab" id="tab1">
					<div id="table_wrapper" style="width: 100%; overflow: auto;">
						<table class="table" cellpadding="0" cellspacing="0">
							<thead>
								<tr>
									<th><b>请选择要进行授权的用户类型：<select id="userTypeSelect"
											onchange="changeUserType(this);">
												<option value="-1">请选择</option>
												<c:forEach var="c" items="${userTypeMap }">
													<option value="${c.key }">${c.value }</option>
												</c:forEach>
										</select><input type="button" value="确定" onclick="changeUserRights();" /></b></th>
								</tr>
							</thead>
						</table>
						<table class="table" cellpadding="0" cellspacing="0">
							<c:forEach var="c" items="${competenciaList }">
								<tr>
									<td><input type="checkbox" id="competencia_${c.id }"
										name="competencia" value="${c.id }" /></td>
									<td>${c.name }</td>
									<td>${c.url }</td>
								</tr>
							</c:forEach>

						</table>
					</div>
				</div>
			</div>
		</div>
	</div>
</body>
</html>

